package code3;

/**
 * @author noob
 * @version 1.0
 * @date 2021/3/16 10:45
 * 数组中的逆序对个数
 */
public class Test1 {

    public static <E extends Comparable<E>>  int count(E[] arr){
        int n = arr.length;
        int count = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i+1; j < n; j++) {
                if(arr[i].compareTo(arr[j]) > 0){
                    count++;
                }
            }
        }
        return count;

    }



    public static void main(String[] args) {
        Integer [] arr = {1,2,3,4,5,6,7};
        int count = Test1.count(arr);
        System.out.println(count);


        Integer[] arr2 = {7,5,6,4};
        int count1 = Test1.count(arr2);
        System.out.println(count1); //5 正确 暴力解法：leetcode会超时
    }
}
